var t = getApp();

Page({
    data: {
        explain: !1,
        swlist: [],
        upper_limit: [],
        info: [],
        swlistImg: []
    },
    onLoad: function(t) {
        this.getData();
        console.log([ {
            code_url: "二维码1",
            upper_limit: 300
        }, {
            code_url: "二维码2",
            upper_limit: 300
        } ]);
    },
    name: function(t) {
        var e = t.detail.value;
        this.setData({
            code_name: e
        });
    },
    guide: function(t) {
        var e = t.detail.value;
        this.setData({
            code_guide: e
        });
    },
    service_guide: function(t) {
        var e = t.detail.value;
        this.setData({
            customer_service_guide: e
        });
    },
    change: function(t) {
        console.log(t);
        var e = t.detail.value;
        this.setData({
            explain: e
        });
    },
    change1: function(t) {
        var e = t.detail.value;
        this.setData({
            recommend: e
        });
    },
    onRead: function() {
        var e = this, a = t.getNetAddresss("upload.uploadPic");
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(t) {
                var s = t.tempFilePaths;
                wx.compressImage({
                    src: s[0],
                    quality: 60,
                    success: function(t) {
                        wx.showLoading({
                            title: "上传中"
                        });
                        var s = t.tempFilePath;
                        wx.uploadFile({
                            url: a,
                            filePath: s,
                            name: "file",
                            success: function(t) {
                                wx.hideLoading({
                                    success: function(t) {}
                                });
                                var a = JSON.parse(t.data);
                                1 == a.result ? (console.log(s, a.data.img), e.setData({
                                    imageUrl: a.data.img,
                                    customer_service: a.data.img_url
                                })) : wx.showToast({
                                    icon: "none",
                                    title: a.msg,
                                    duration: 1500
                                });
                            }
                        });
                    },
                    fail: function(t) {},
                    complete: function(t) {}
                });
            }
        });
    },
    onRead_2: function() {
        var t = this;
        wx.chooseImage({
            count: 9,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(e) {
                console.log(e.tempFilePaths), t.unload({
                    tempFilePaths: e.tempFilePaths
                }, "1");
            }
        });
    },
    unload: function(e, a) {
        console.log(a), wx.showLoading({
            title: "上传中"
        });
        var s = t.getNetAddresss("upload.uploadPic"), i = this, o = e.i ? e.i : 0, n = e.success ? e.success : 0, l = e.fail ? e.fail : 0;
        wx.uploadFile({
            url: s,
            filePath: e.tempFilePaths[o],
            name: "file",
            formData: null,
            success: function(t) {
                wx.hideLoading({
                    success: function(t) {}
                });
                var e = JSON.parse(t.data);
                console.log(e.data.img_url), "1" == a ? (i.data.swlistImg.push(e.data.img), i.data.swlist.push(e.data.img_url), 
                i.setData({
                    code_url: i.data.swlist,
                    swlistImg: i.data.swlistImg
                })) : 2 == a && (i.data.swlis.push(e.data.img_url), i.setData({
                    code_url: i.data.swlis,
                    swlistImg: i.data.swlistImg
                })), console.log(i.data.code_url);
            },
            fail: function(t) {
                wx.hideLoading({
                    success: function(t) {}
                }), l++;
            },
            complete: function(t) {
                wx.hideLoading({
                    success: function(t) {}
                }), ++o == e.tempFilePaths.length ? (console.log("执行完毕"), console.log("成功：" + n + " 失败：" + l)) : (e.i = o, 
                e.success = n, e.fail = l, i.unload(e, a));
            }
        });
    },
    delImg: function(t) {
        var e = t.currentTarget.dataset.ind, a = this.data.code_url, s = this.data.swlistImg;
        a.splice(e, 1), s.splice(e, 1), console.log(a, "截取后"), console.log(s, "截取后"), this.setData({
            code_url: a,
            swlistImg: s
        });
    },
    upperLimit: function(t) {
        console.log(t);
        var e = t.detail.value, a = t.currentTarget.dataset.ind, s = this.data.upper_limit;
        s[a] = e, this.setData({
            upper_limit: s
        });
    },
    explaincon: function(t) {
        var e = t.detail.value;
        this.setData({
            explain_content: e
        });
    },
    onReady: function() {},
    onShow: function() {
        this.getset();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getData: function() {
        var e = this, a = t.getNetAddresss("plugin.group-code.api.group-code.add");
        t._postNetWork({
            url: a,
            success: function(t) {
                var a = t.data;
                1 == a.result ? (console.log(a), e.setData({
                    info: a.data.set
                })) : (wx.showToast({
                    title: a.msg,
                    icon: "none"
                }), console.log(a.msg));
            }
        });
    },
    getset: function() {
        var e = this, a = t.getNetAddresss("plugin.group-code.api.set.index");
        t._postNetWork({
            url: a,
            success: function(t) {
                var a = t.data;
                1 == a.result ? (console.log(a), e.setData({
                    is_open: a.data.set.is_open,
                    auth_recommend: a.data.set.auth_recommend
                })) : (wx.showToast({
                    title: a.msg,
                    icon: "none"
                }), console.log(a.msg));
            }
        });
    },
    save: function() {
        if (t._isTextEmpty(this.data.code_name)) wx.showToast({
            title: "请输入群活码名称",
            icon: "none",
            duration: 1e3
        }); else if (this.data.explain && t._isTextEmpty(this.data.explain_content)) wx.showToast({
            title: "请输入说明内容",
            icon: "none",
            duration: 1e3
        }); else if (t._isTextEmpty(this.data.customer_service)) wx.showToast({
            title: "请输入客服二维码",
            icon: "none",
            duration: 1e3
        }); else if (t._isTextEmpty(this.data.customer_service_guide)) wx.showToast({
            title: "请输入客服引导语",
            icon: "none",
            duration: 1e3
        }); else if (t._isTextEmpty(this.data.code_guide)) wx.showToast({
            title: "请输入群活码引导语",
            icon: "none",
            duration: 1e3
        }); else if (t._isTextEmpty(this.data.code_url)) wx.showToast({
            title: "请上传群二维码url",
            icon: "none",
            duration: 1e3
        }); else {
            if (this.data.upper_limit.length < this.data.code_url.length) return console.log(this.data.upper_limit.length, this.data.code_url.length), 
            console.log(this.data.upper_limit, this.data.code_url), console.log("请输入扫码上限人数"), 
            void wx.showToast({
                title: "请输入扫码上限人数",
                icon: "none",
                duration: 1e3
            });
            for (var e = [], a = 0; a < this.data.code_url.length; a++) e.push({
                code_url: this.data.swlistImg[a],
                upper_limit: this.data.upper_limit[a]
            });
            var s = {
                code_data: JSON.stringify(e),
                code_name: this.data.code_name,
                code_guide: this.data.code_guide,
                recommend: this.data.recommend ? "1" : "0",
                explain: this.data.explain ? "1" : "0",
                explain_content: this.data.explain_content,
                customer_service: this.data.imageUrl,
                customer_service_guide: this.data.customer_service_guide
            };
            this.saveSubmit(s);
        }
    },
    saveSubmit: function(e) {
        var a = t.getNetAddresss("plugin.group-code.api.group-code.create");
        t._postNetWork({
            url: a,
            data: e,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (console.log(e), wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3,
                    success: function() {
                        wx.navigateBack({
                            delta: 1
                        });
                    }
                })) : (wx.showToast({
                    title: e.msg,
                    icon: "none"
                }), console.log(e.msg));
            }
        });
    }
});